export default class PsnInfoAction {
    constructor(comp) {
        this.comp = comp;
    }

    // 获取一条数据
    getPsnInfoData = async (selectedRows) => {
        const {props} = this.comp;
        const {form, dispatch, button, emp} = props;
  
        let postData = {
            pk_psndoc: selectedRows[0].values['pk_psndoc'].value,
            pk_org: emp.orgValue.refpk
        };

        try {
            let res = await dispatch({
                type: 'emp/getPsnInfoData',
                payload: {
                    postData: postData
                }
            });

            if(res.success) {
                return res;
            }
        }
        catch(e) {
            return false;
        }

        return true;
    }

    // 联查员工信息
    qryPsnInfo = async (selectedRows) => {
        const {props} = this.comp;
        const {dispatch} = props;

        try {
            let oneBillData = await this.getPsnInfoData(selectedRows);
            
            if(oneBillData) {
                dispatch({
                    type: 'emp/update',
                    payload: {
                        addPageDisp: 'none',
                        psnInfoDisp: 'block',
                        addBtnDisp: 'none'
                    }
                });
            }
            this.toBrowseStatus(oneBillData.data);       
        }
        catch(e) {
            console.error(e)
        }  
    }

    // 表单进入浏览态
    toBrowseStatus = (formValue) => {
        const {props} = this.comp;
        const {form, editTable} = props;

        // 填充表单的值
        if(formValue) {
            if(formValue.bd_psndoc){
                form.setAllFormValue({
                    bd_psndoc: formValue.bd_psndoc.bd_psndoc
                });
            }
            if(formValue.hi_psndoc_work){
                editTable.setTableData('hi_psndoc_work', formValue.hi_psndoc_work.hi_psndoc_work, false);
            }
            if(formValue.hi_psndoc_edu){
                editTable.setTableData('hi_psndoc_edu', formValue.hi_psndoc_edu.hi_psndoc_edu, false);
                }
            if(formValue.hi_psndoc_family){
                editTable.setTableData('hi_psndoc_family', formValue.hi_psndoc_family.hi_psndoc_family, false);
            }
            if(formValue.hi_psndoc_linkman){
                editTable.setTableData('hi_psndoc_linkman', formValue.hi_psndoc_linkman.hi_psndoc_linkman, false);
            }       
        }
    }
}